<template>
  <div class="project-app">
    <div class="header">
      <a-carousel autoplay>
        <div class="swiper" v-for="(project, index) in projects" :key="index">
          <img class="swiper-img" :src="project.imgs.split(' ')[0]" alt="" />
        </div>
      </a-carousel>
    </div>
    <div class="main">
      <div v-for="(project, index) in projects" :key="index" class="project">
        <div class="inner">
          <div class="img">
            <img :src="project.imgs.split(' ')[0]" alt="" />
          </div>
          <div class="box-">
            <h1 class="title">
              {{ project.projectName }}
              <div class="tag">
                <a-tag
                  v-for="(tag, index) in project.tag.split(' ')"
                  :key="index"
                  :color="colors[index]"
                  >{{ tag }}</a-tag
                >
              </div>
            </h1>

            <div class="desc">{{ project.des }}</div>
          </div>
          <button @click="jumpDetail(project.id)" class="detail-btn">
            了解详情
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { reactive, toRefs } from "vue";
import { getProByUserId } from "@/api/project";
import { useRoute, useRouter } from "vue-router";
export default {
  async mounted() {
    await this.initData();
  },

  setup() {
    const route = useRoute();
    const router = useRouter();
    const initData = async () => {
      const id = route.params.id;
      const res = await getProByUserId(id);
      if (res) {
        state.projects = res.data;
      }
    };
    const jumpDetail = (detailId) => {
      router.push(`/projectdetail/${detailId}`);
    };
    const state = reactive({
      projects: [],
      initData,
      jumpDetail,
      colors: ["green", "red", "pink", "cyan"],
    });
    return { ...toRefs(state) };
  },
};
</script>

<style lang="scss" scoped>
@media screen and (max-width: 500px) {
  .project-app {
    .main {
      display: block;
      .project {
        width: 100% !important;
      }
    }
  }
}
.ant-carousel :deep(.slick-slide) {
  text-align: center;
  // width: 600px;
  height: 400px;
  line-height: 360px;
  background: #364d79;
  overflow: hidden;
}

.ant-carousel :deep(.slick-slide h3) {
  color: #fff;
}
.project-app {
  background-color: white !important;
  .header {
    .swiper {
    }
  }
  .main {
    display: flex;
    // justify-content: center;
    flex-wrap: wrap;
    .project {
      // flex: 1;
      min-width: 33.3%;
      position: relative;
      text-align: center;
      .inner {
        margin-top: 80px;
        transition: all 0.5s ease-in-out;
        .desc {
          text-align: left;
          color: #73747b;
          font-size: 12px;
          padding: 0px 15px;
          // overflow: hidden;
          // text-overflow: ellipsis;
          // white-space: nowrap;
          line-height: 16px;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          overflow: hidden;
        }
      }
      .detail-btn {
        position: absolute;
        width: 120px;
        height: 40px;
        line-height: 40px;
        color: #fff;
        background: #00b8ff;
        border: none;
        opacity: 0;
        border-radius: 0px;
        transition: 0.5s;
        font-size: 16px;
        text-align: center;
        outline: none;
        left: 50%;
        margin-left: -60px;
        bottom: 20px;
        overflow: hidden;
        &:hover {
          // border-radius: 20px;
          &::before {
          }
        }
        &::before {
          content: "";
          position: absolute;
          top: 0;
          left: 0;
          width: 100%;
          height: 100%;
          background: #37474f;
          z-index: -1;
          opacity: 0;
        }
      }

      .title {
        font-size: 22px;
        position: relative;
        .tag {
          margin: 15px 0px;
        }
      }
      &::before {
        content: "";
        width: 0px;
        height: 3px;
        background: #00b8ff;
        top: 0;
        left: 0;
        position: absolute;
        z-index: 999;
        transition: 1s;
      }
      &:hover {
        box-shadow: 0 2px 20px rgba(175, 175, 175, 0.3);
        .inner {
          margin-top: 50px;
        }
        .detail-btn {
          opacity: 1;
        }
        &::before {
          width: 100%;
        }
      }
      width: 33%;
      height: 428px;
      border: 1px solid #e7e7e7;
      text-align: center;
      .img {
        margin: 10px auto;
        display: flex;
        justify-content: center;
        text-align: center;
        img {
          width: 300px;
          height: 180px;
          object-fit: contain;
        }
      }
    }
  }
}
</style>